from typing import *
from math import inf


class Solution:

    def minCost(self, nums: List[int], x: int) -> int:
        ans, n = inf, len(nums)
        mn = [inf] * n
        for i in range(n):
            c = 0
            for j in range(n):
                mn[j] = min(mn[j], nums[(j - i + n) % n])
                c += mn[j]
            ans = min(ans, i * x + c)
        return ans


class Solution:

    def minCost(self, nums: List[int], x: int) -> int:
        ans, n = inf, len(nums)
        mn = [inf] * n
        for i in range(n):
            for j in range(n):
                mn[j] = min(mn[j], nums[(j - i + n) % n])
            ans = min(ans, i * x + sum(mn))
        return ans